package com.cta.view.controller;

import java.util.ArrayList;
import java.util.List;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cta.service.ReportService;
import com.cta.service.SiteService;
import com.cta.view.json.tree.TariffEntityTreeNode;
import com.cta.view.model.report.ReportParams;

@Controller
public class ReportController extends BasicController {


	@Autowired
	private SiteService siteService;

	@Autowired
	private ReportService reportService;

	@RequestMapping(value = "/loadEntityTree.html", method = RequestMethod.GET)
	@ResponseBody
	public List<TariffEntityTreeNode> loadEntityTree() {
		try {
			return reportService.loadEntity();
		} catch (Exception e) {
			log.error("Error: ", e);
			return new ArrayList<TariffEntityTreeNode>();
		}
	}
	
	@RequestMapping(value = "/runReport.html", method = RequestMethod.POST)
	@ResponseBody public String runReport(String type, String entity, String period) {
		try {
			reportService.runReport(new ReportParams(type, entity, period));
			return "";
		} catch (Exception e) {
			log.error("Error: ", e);
			return "";
		}
	}

}
